URL = "http://bzip.org/%(VERSION)s/bzip2-%(VERSION)s.tar.gz"
VERSIONS = ["1.0.6"]
DEFAULT_VERSION = "1.0.6"

from source.builders import GenericBuilder
import os, shutil

class BZip2Builder( GenericBuilder ):
  """ subclass of GenericBuilder """ 
  def hasdebug(self):
    return False

  def install(self ):
    os.chdir( self.extractedpath )
    if self.machine.isLinux():
      #static version:
      #self.execute( "make install PREFIX="+self.targetpath )
      #self.execute( "make clean" )

      if self.runtime.build_linktype == "shared":
      #dynamic version (boost needs dynamic version)
        self.execute( "make -f Makefile-libbz2_so PREFIX="+self.targetpath() )
        self.execute( "make install PREFIX="+self.targetpath() )
        shutil.copy( "libbz2.so."+self.version, self.getlibdir()+os.sep+"libbz2.so."+self.version)
        solink = "libbz2.so."+self.version[:3]
        if os.path.exists(self.getlibdir()+os.sep+solink):
          os.remove( self.getlibdir()+os.sep+solink )
        shutil.move( "libbz2.so."+self.version[:3], self.getlibdir())
      else:
        self.execute( "make PREFIX="+self.targetpath() )
        self.execute( "make install PREFIX="+self.targetpath() )

    else:
      self.execute( "nmake -f makefile.msc" )

      #windows version comes without install target
      #explicitly install (bin, lib, include)
      bindir = self.getbindir()
      if not os.path.exists(bindir): os.makedirs(bindir)
      shutil.copy( "bzip2.exe", bindir )
      shutil.copy( "bzip2recover.exe", bindir )

      libdir = self.getlibdir()
      if not os.path.exists(libdir): os.makedirs(libdir)
      shutil.copy( "libbz2.lib", libdir )

      includedir = self.getincludedir()
      if not os.path.exists(includedir): os.makedirs(includedir)
      shutil.copy( "bzlib.h", includedir )
    #if not os.path.exists( self.targetpath() ):
    #  os.makedirs( self.targetpath )


BUILDER = BZip2Builder

